package com.yiwei.zhh.api.requestInfo;

import com.yiwei.zhh.api.Api;
import com.yiwei.zhh.api.bean.NickNameBean;
import com.yiwei.zhh.api.callback.NickNameContract;
import com.yiwei.zhh.util.Network;
import com.yiwei.zhh.util.RxLifeUtil;
import com.yiwei.zhh.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class NickNameRequest extends BaseRequest<NickNameContract.View> implements NickNameContract.Presenter<NickNameContract.View> {

    public static NickNameRequest create() {
        return new NickNameRequest();
    }


    @Override
    public void getNickname(String nickname) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        NickNameBean bean = new NickNameBean();
        bean.nickname = nickname;
        Api.api_service.getNicknameInfo(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getNicknameSuccess(result);
                });
    }
}
